home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / VISUALBA / PROG913.ZIP / PROGTEXT.DOC < prev    next >
Text File  |  1994-02-08  |  40KB  |  948 lines

  1. PROGTEXT.DOC - by:  Ira F. Kavaler - March and April, 1987
  2.  
  3.  
  4. Beginner's BASIC - Ira F. Kavaler - 3/14/85 - 1/8/94
  5.  
  6.  
  7. The BASIC Language.
  8. -------------------
  9.  
  10.      BASIC is the name of a high-level computer language that is
  11. furnished with the vast majority of personal computers.  BASIC stands
  12. for Beginners All-Purpose Symbolic Instruction Code.  BASIC is not a
  13. new language;  it has been in use for 25 years.  It is not an original
  14. language;  it was derived from the most popular language of all time,
  15. FORTRAN (FOrmula TRANslator).  Both of these languages were created for
  16. scientists and engineers;  however, since both have become very easy to
  17. use in the past decade, almost every field where computers can be
  18. beneficial, BASIC (and FORTRAN) can be used as a general purpose
  19. programming language.
  20.  
  21.      BASIC consists of a set of "commands".  A command is a word or  an
  22. abbreviation that tells the computer to perform a task.  Commands
  23. usually require some additional information called "arguments" which
  24. specify the object of the task.  An instruction or "statement" contains
  25. the total information, command and argument(s).  The statements are
  26. arranged in a logical sequence to produce a "program".
  27.  
  28.  
  29. Line Numbers.
  30. -------------
  31.  
  32.      If you have ever followed a set of instructions you have noticed
  33. that each instruction is given a number.  This number serves two
  34. purposes:
  35.  
  36. 1.   To determine the proper order (sequence) of the instructions, and
  37. 2.   To provide a reference to any specific instruction should that
  38.      become necessary.
  39.  
  40.      The computer program also uses such a numbering system for the
  41. same reasons;  each statement number is called a "line number" since
  42. each statement in the program is usually written one to a line.  "Line
  43. numbers" must be positive integers;  that is, zero, negative numbers,
  44. and non-whole numbers areNot allowed.
  45.  
  46.      You might want to number your lines starting with "1" and
  47. continuing, incrementing the number by one, until all lines have been
  48. numbered.  Although there is no reason why this method would not work,
  49. a much better practice is to start with line number "10" and continue
  50. incrementing each subsequent line number by ten.  The advantage is that
  51. if you have forgotten a statement in theMiddle of the program, you will
  52. have unused numbers in-between the existing line numbers.
  53.  
  54.      Nearly 90% of all computer programs can be written using only six
  55. easily understood elementary commands: LET, PRINT, INPUT, GOTO,
  56. IF...THEN, and END.  There are dozens of other commands that make
  57. writing a program a very simple and concise task; however, you will
  58. discover that they areSubstitutes for commonly encountered sequences of
  59. the six elementary commands.Numeric constants.
  60.  
  61.      For many years the art of computer programming was kept a deep,
  62. dark secret by the mathematicians of the world.  By the way, computer
  63. programmers were called mathematicians in the "olden days" (1930's
  64. through 1960's).  In order to retain the secret, many mysterious terms
  65. were either adopted or coined for the computer and programming
  66. vocabulary;  "constant" is such a term.  A "constant" is a number which
  67. represents a quantity or an amount.  In general, a "constant" is
  68. anything that is fixed in value.  To be more precise, this type of
  69. constant is called a "numeric constant", as it only pertains to
  70. quantities or amounts.  Constants are like the numbers you would enter
  71. into a calculator:
  72.  
  73.      the digits zero "0" through nine "9",
  74.      the decimal point ".",
  75.      the plus "+" and minus "-" signs
  76.           (which denote positive and negative Numbers), and
  77.      the letter "E" (exponent) is also used as a symbol to indicate
  78.           scientific notation (10 to a power).
  79.  
  80. On a scientific calculator the key is labelled either "EE" (enter
  81. exponent) or "EXP".
  82.  
  83.      1234567890 = 1.23456789 X 10 (to the 9th power)
  84.                 = 1.23456789E+9
  85.  
  86.      0.0002468 = 2.468 X 10 (to the minus 4th power)
  87.                = 2.468E-4
  88.  
  89.      There is another category called "string constants" that involves
  90. names, addresses, dates, etc.  "Strings" will be covered at a later
  91. time.
  92.  
  93.  
  94. Flow Charting.
  95. --------------
  96.  
  97.      The easiest way to start writing a program is to diagram it;  that
  98. is, diagram the steps necessary to solve the problem.  Over the years
  99. some symbols have been adopted by different disciplines for this
  100. purpose.  These symbols are not standardized, and are left to you to
  101. use what you feel confortable using.  The following are my set:
  102.  
  103. BASIC Command           Flow chart symbol
  104. -------------           -----------------
  105. LET                     a rectangle
  106. INPUT                   a rectangle with the upper left corner cut-off
  107.                         (so it looks like a computer punch card)
  108. PRINT                   a rectangle with a one cycle sine wave at the
  109. bottom
  110.                         (so it looks like a sheet of paper torn-off)
  111. STOP or END             an octagon
  112.                         (so it looks like a stop sign)
  113. IF...THEN               a diamond
  114. the program first line  an upside-down triangle
  115.                         (so it looks like a yield sign)
  116. GOTO                    a circle (see text)
  117.  
  118.      The flow chart symbols are interconnected with arrows showing the
  119. direction of progress from one command to the next.  Exclding the
  120. IF...THEN diamond, each symbol can only have one aroow leaving it, but
  121. can have one or more arrows poinmting to it.
  122.  
  123.      The IF...THEN diamond must have only two arrows leaving it, one if
  124. the logical expression is evaluated "true" and the other if the logical
  125. expression is evaluated "false".  It can have one or more arrows
  126. poinmting to it.
  127.  
  128.      The STOP or END octagon cannot have any leaving arrows.  (There is
  129. one very advacned condition, where a CONTINUE command is executed, that
  130. allows for a leaving arrow, but it is seldom used.)
  131.  
  132.      The GOTO is normally not symbolized, the arrows are just drawn to
  133. indicate the path of the GOTO;  however, if the destination of the GOTO
  134. is far away from the source of the GOTO, or it is on another sheet of
  135. paper, etc., the source GOTO is terminated in a circle which has a
  136. specific label;  the destination of the GOTO originates at a circle
  137. having the same label, with an arrow to the destination command.
  138.  
  139.      The REM command is not indicated on the flow chart.
  140.  
  141.  
  142. Numeric Variables.
  143. ------------------
  144.  
  145.      As some of the better calculators have memories which can hold
  146. numbers, the computer also has memories.  Usually the calculator's
  147. memories will be numbered:  M1, M2, M3, etc.  One problem is that you
  148. must remember which memory holds what constant.
  149.  
  150.      The computer does not number the memories, but instead allows you
  151. to give them names.  If you wanted the computer to hold the balance of
  152. your checking account, you could call it BALANCE.  The computer will
  153. automatically assign one of its memories for this purpose and use it
  154. anytime you specify BALANCE.  Similarly, you could hold the deposit you
  155. made to your account as DEPOSIT, and there would be no problem.  In
  156. fact, the computer has the ability to hold hundreds of memories,
  157. limited only by the "size" of your computer system.  These so-called
  158. memories that you can name for your specific purpose are called
  159. "variables", and since they hold "numeric constants", they are called
  160. "numeric variables".  But I now must clarify one point;  most computers
  161. only use the first two characters of the variable name, although your
  162. name may be upto 16 characters long.  The IBM and compatibles use all
  163. 16 characters.  Consider a program where you are a farmer and have to
  164. keep track of how many apples and apricots you have harvested.  If you
  165. use the variable names APPLES and APRICOTS, most computers will not
  166. keep the two constants in separate variables;  both "APPLES and
  167. APRICOTS start with the same two letters "AP", and if the computer only
  168. uses the first two characters when it assigns memory to the variable
  169. names.  You will have to choose a different name for one of the two
  170. names, such as "ap" for apples and "ar" f